import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Test {
    static Map<String,Integer> map = new HashMap<>();
    static void main(){
        map.put("3",1);
        map.put("4",2);
        map.put("5",3);
        map.put("6",4);
        map.put("7",5);
        map.put("8",6);
        map.put("9",7);
        map.put("10",8);
        map.put("J",9);
        map.put("Q",10);
        map.put("K",11);
        map.put("A",12);
        map.put("2",13);
        map.put("joker",14);
        map.put("JOKER",15);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        main();
        while (in.hasNextLine()) {
            String str = in.nextLine();
            String[] strings = str.split("-");
            String[] one = strings[0].split(" ");
            String[] two = strings[1].split(" ");
            String[] ret = {};
            if(one.length == two.length){
                if(isBoom(one) && !isBoom(two)){
                    ret = one;
                }else if(isBoom(two) && !isBoom(one)){
                    ret = two;
                }else {
                    ret = map.get(one[0]) > map.get(two[0]) ? one : two;
                }
            }else {
                if(isBoom(one) && !isBoom(two)){
                    ret = one;
                }else if(isBoom(two) && !isBoom(one)){
                    ret = two;
                }else {
                    ret = map.get(one[0]) > map.get(two[0]) ? one : two;
                }
            }
            for (int i = 0; i < ret.length; i++) {
                System.out.print(ret[i] + " ");
            }
        }
    }
    public static boolean isBoom(String[] str){
        if(str.length == 2){
            return map.get(str[0])+map.get(str[1]) == 29;
        }
        if(str.length == 4){
            return str[0].equals(str[1]) && str[0].equals(str[2]) && str[0].equals(str[3]);
        }
        return false;
    }
}
